#include "ReviewUIProxy.hpp"

#define MACRO_CREATE_NAME(val) func##val
#define MACRO_STR(val) #val
#define REGISTER_METHOD_MACRO(name) \
  obj->registerMethod(MACRO_STR(name)).onInterface(InterfaceName).implementedAs(MACRO_CREATE_NAME(name));

ReviewUIProxy::ReviewUIProxy()
{
}

ReviewUIProxy::~ReviewUIProxy()
{
  if(workThread.joinable())
  {
    conn->leaveEventLoop();
    workThread.join();
  }
}


void ReviewUIProxy::Boot()
{
  conn=sdbus::createSessionBusConnection(InterfaceName);
  obj=sdbus::createObject(*conn,"/org/HBTY/ReviewUI");
  REGISTER_METHOD_MACRO(GetAllTaskList);
  REGISTER_METHOD_MACRO(GetHandleFinishRecordList);
  REGISTER_METHOD_MACRO(GetHandleFinishRecordListWithTask);
  REGISTER_METHOD_MACRO(GetRecordList);
  REGISTER_METHOD_MACRO(GetTaskInf);
  REGISTER_METHOD_MACRO(GetRecordInf);
  REGISTER_METHOD_MACRO(GetCameraIDList);
  REGISTER_METHOD_MACRO(OutputData);
  obj->finishRegistration();

  workThread=std::thread([this](){
    conn->enterEventLoop();
  });
}


